package ar.edu.unicen.pladema.ui.model.g3d;

public class Vertex {
	private String pX;
	private String pY;
	private String pZ;
	private double dX;
	private double dY;
	private double dZ;
	private Double module=null;
	
	public void setX(String token) {
		pX = token;
		dX = Double.parseDouble(token);
	}
	public void setY(String token) {
		pY = token;
		dY = Double.parseDouble(token);
	}
	public void setZ(String token) {
		pZ = token;
		dZ = Double.parseDouble(token);
	}
	public void setDX(double x) {
		dX = x;
		pX = Double.toString(x);
	}
	public double getDX() {
		return dX;
	}
	public void setDY(double y) {
		dY = y;
		pY = Double.toString(y);
	}
	public double getDY() {
		return dY;
	}
	public void setDZ(double z) {
		dZ = z;
		pZ = Double.toString(z);
	}
	public double getDZ() {
		return dZ;
	}
	@Override
	public String toString() {
		return "["+pX+","+pY+","+pZ+"]";
	}
	public double scalar(Vertex other) {
		double result = (this.dX * other.dX) + (this.dY * other.dY) + (this.dZ * other.dZ); 
		return result;
	}
	public double getModule() {
		if (module == null) {
			module = Math.sqrt(
					(dX * dX) +
					(dY * dY) +
					(dZ * dZ) );
		}
		return module;
	}
	public Vertex getNormalized() {
		Vertex result = new Vertex();
		result.setDX(getDX() / getModule());
		result.setDY(getDY() / getModule());
		result.setDZ(getDZ() / getModule());
		return result;
	}
	
}
